package com.fashiontextile.user.service.impl;

import com.fashiontextile.common.entity.R;
import com.fashiontextile.user.entity.Role;
import com.fashiontextile.user.entity.User;
import com.fashiontextile.user.mapper.UserMapper;
import com.fashiontextile.user.service.UserService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author brooke_zb
 */
@Service
@AllArgsConstructor
public class UserServiceImpl implements UserService {
    private UserMapper userMapper;

    @Override
    public User selectByUid(Long uid) {
        return userMapper.selectByUid(uid);
    }

    @Override
    public User selectByUsername(String username) {
        return userMapper.selectByUsername(username);
    }

    @Override
    public User selectByEmail(String email) {
        return userMapper.selectByEmail(email);
    }

    @Override
    public Integer updateEmail(String newEmail, Long uid) {
        return userMapper.updateEmail(newEmail, uid);
    }

    @Override
    public Integer updateAvatar(String avatarUrl, Long uid) {
        return userMapper.updateAvatar(avatarUrl, uid);
    }

    @Override
    public Integer updatePasswold(String newpasswold, Long uid) {
        return userMapper.updatePasswold(newpasswold, uid);
    }

    @Override
    public Integer insertUser(User user) {
        return userMapper.insertUser(user);
    }

    @Override
    public List<User> getAllUser(String keyword) {
        return userMapper.getAllUser(keyword);
    }

    @Override
    public Integer updateUserStatus(Long uid, Integer enable) {
        return userMapper.updateUserState(uid, enable);
    }

    @Override
    public R<?> changeRoleByUid(long uid, Integer rid) {
        Integer changeResult = userMapper.changeRoleByUid(uid, rid);
        return changeResult>0? R.success("角色更改成功"):R.fail("角色更失败");
    }
}
